package com.zhangqie.dnui.demo2.demo3;

import java.text.CollationKey;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

/**
 * Created by zhangqie on 2018/9/20
 * Describe:
 */
public class Demo3 {


    public static void main(String[] args) {
        System.out.println("Hello World");
        List<String> list = new ArrayList<>();
        list.add("Bli");
        list.add("Aa");
        list.add("Ccn");
        list.add("Bal");
        list.add("dm");
        list.add("Dn");
        list.add("lm");
        list.add("cm");
        list.add("aaa");
        Collections.sort(list);

        String[] strings = new String[]{"ba","aa","CC","Ba","DD","ee","dd"};
        Arrays.sort(strings);
        for (int i = 0; i < strings.length; i++) {
            System.out.print(strings[i]+"----");
        }



        System.out.print(list+"\n");




        //汉字排序  java中中文字符串按首字母排序
        List<String> data = new ArrayList<String>();
        data.add("上海");
        data.add("天津");
        data.add("北京");
        data.add("深圳");
        data.add("广州");
        data.add("成都");
        data.add("西安");
        data.add("武汉");
        data.add("郑州");
        data.add("邯郸");

        Collections.sort(data, new Comparator<String>() {
            Collator collator = Collator.getInstance(Locale.CHINA);

            @Override
            public int compare(String o1, String o2) {
                CollationKey key1 = collator.getCollationKey(o1);
                CollationKey key2 = collator.getCollationKey(o2);
                return key1.compareTo(key2);
            }
        });

        for (String str : data) {
            System.out.print(str+"--");
        }
    }










}
